import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
  state: () => ({
    // 侧边栏状态
    sidebarCollapsed: false,
    
    // 面包屑导航
    breadcrumbs: [
      { title: '首页', path: '/dashboard' }
    ],
    
    // 页面加载状态
    loading: false,
    
    // 主题设置
    theme: 'light',
    
    // 系统配置
    config: {
      title: 'ERP管理系统',
      version: '1.0.0',
      logo: '/favicon.ico'
    }
  }),

  getters: {
    // 获取当前页面标题
    pageTitle: (state) => {
      if (state.breadcrumbs.length > 0) {
        return state.breadcrumbs[state.breadcrumbs.length - 1].title
      }
      return state.config.title
    }
  },

  actions: {
    // 切换侧边栏状态
    toggleSidebar() {
      this.sidebarCollapsed = !this.sidebarCollapsed
    },

    // 设置侧边栏状态
    setSidebarCollapsed(collapsed) {
      this.sidebarCollapsed = collapsed
    },

    // 设置面包屑导航
    setBreadcrumbs(breadcrumbs) {
      this.breadcrumbs = breadcrumbs
    },

    // 添加面包屑
    addBreadcrumb(breadcrumb) {
      this.breadcrumbs.push(breadcrumb)
    },

    // 设置加载状态
    setLoading(loading) {
      this.loading = loading
    },

    // 切换主题
    toggleTheme() {
      this.theme = this.theme === 'light' ? 'dark' : 'light'
    },

    // 设置主题
    setTheme(theme) {
      this.theme = theme
    }
  }
})
